home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 1.iso / toolbox / www / cgi-bin / tar-cgi < prev    next >
Encoding:
Text File  |  1996-11-11  |  7.8 KB  |  217 lines

  1. #!/usr/bin/perl
  2.  
  3. # This should match the mail program on your system.
  4. $mailprog = '/usr/lib/sendmail';
  5. # Who do you want the mail to get to who as...
  6. $recipient = 'DTjanitor\@sgi.com';
  7.  
  8. #get user home directory from this file
  9. eval (`cat "/tmp/.userhome_$ENV{'SERVER_PORT'}"`);
  10.  
  11. #####################################
  12. # Setup/Define Machine-Specific stuff
  13. chop($server=`hostname`);
  14. # make the $userHome/.www_6.0/.DT_DocRootFile, specified below, have it's contents
  15. # equal to the equivalent-on-your-machine of everything *inside* the
  16. # single, "'", quotes:  '$DocumentRoot="/AbsPath/to/your/DocRoot"'
  17. $DocumentRoot=$ENV{'DOCUMENT_ROOT'};
  18. &docroot_failure unless $DocumentRoot;
  19.  
  20.  
  21. # Print out a content-type for HTTP/1.0 compatibility
  22. # --the next line tells the browser this doc will be html:
  23. print "Content-type: text/html\n\n";
  24.  
  25.  
  26.  
  27. # 1. save out the HTTP env var's we're *REALLY* interested in: 
  28.  
  29. #   PATH_* var's are defined in terms of the dir location where
  30. #   the html file is which invokes this cgi-bin script
  31.  
  32. # PATH_INFO is the "relative path" from Doc root (with a leading `/' char)
  33. $relpath2parentdir = $ENV{'PATH_INFO'};
  34. # PATH_TRANSLATED is the absolute path from / 
  35. $abspath2parentdir = $ENV{'PATH_TRANSLATED'};
  36.  
  37. # QUERY_STRING stores the name of the subdir who's "parent dir" is 
  38. # is the one that PATH_INFO and PATH_TRANSLATED point to.
  39. $dir2tar = $ENV{'QUERY_STRING'} ;
  40.  
  41.  
  42. # 2. tack on the ".tar.Z" file suffix for the compressed 
  43. #    tar image we're going to create:
  44. $d2tz = "$dir2tar" . ".tar.Z";
  45.  
  46.  
  47. # 3. get a pid number for use as the temporary dir we'll create in
  48. #    /WHATEVER/DOCUMENT/ROOT/IS/tmp to hold the compressed tar image file
  49. #    of the actual original dir name:
  50. $tmpdir = `$DocumentRoot/toolbox/www/cgi-bin/pid` ;
  51.  
  52.  
  53. # 4. create paths we'll be needing further down and in tarsend-cgi:
  54.  
  55. #    make a "return-them-to-whence-they-came-from" url string:
  56. #    FLAW:  this assumes they ALWAYS came from an index.html file
  57. #    AND, the following test covers the special-case of the cgi-bin
  58. #    "index.html" file which can't be in that dir cuz everything in
  59. #    there is executable by the server.  so the www/cgi-bin.html file
  60. #    which is in the cgi-bin parent dir, "stands in" as if it were
  61. #    cgi-bin/index.html....  so the following fixes things when that
  62. #    one special case happens to be the one being transmitted.
  63. if ($dir2tar eq "cgi-bin") {
  64.     $ret2begin = "$relpath2parentdir" . "/cgi-bin.html";
  65. } else {
  66.     $ret2begin = "$relpath2parentdir" . "/$dir2tar/" . "index.html";
  67. }
  68.  
  69. #    make absolute path & path/file strings as well as 
  70. #    a relative path/file string:
  71. $abstmpdirpath = "$DocumentRoot/tmp/" . "$tmpdir" ;
  72. $abstmpdirpathNfile = "$DocumentRoot/tmp/" . "$tmpdir" . "/$d2tz" ;
  73. $reltmpdirpathNfile = "/tmp/" . "$tmpdir" . "/$d2tz" ;
  74.  
  75.  
  76. # 5. create the complete set of shell commands to:
  77. #    make the temporary directory
  78. #    change directory to the parent of the dir to tar up
  79. #    create the tar image of dir we want and pipe it to compress
  80. #    then redirecting compress's output to stdout to the absolute
  81. #    temp file/path name:
  82. chop($cgi_bin = `dirname $0`);
  83. $maketar = "mkdir $abstmpdirpath; cd $abspath2parentdir; tar cLf - $dir2tar | $cgi_bin/DTcompress > $abstmpdirpathNfile";
  84.  
  85.  
  86. # 6. run the "maketar" command inside the system() routine
  87. #    (0 == success, non-0 == failure)
  88. $res = system ("$maketar");
  89.  
  90.  
  91. # 7. test the result of system to confirm the tmp file was
  92. #    successfully made:
  93. if ($res == 0) {
  94.  
  95.   
  96.   # we succeeded, so print out success header
  97.   &header_success ;
  98.  
  99.   # 8 get "ls -l" readout for size of this file:
  100.   @list = split(/[ \t\n]+/, `ls -l $abstmpdirpath/$d2tz`);
  101.   if ($#list == 8) {
  102.       $size = $list[4];
  103.   } else {
  104.       $size = $list[3];
  105.   }
  106.   close(LSLONG);
  107.    
  108.   # 9. construct the guts of the anchor pointing to the tmp file:
  109.   $anchor = "\"$reltmpdirpathNfile\"";
  110.  
  111.   # 10. construct the transmit action used in #11:
  112.   $transmitform = "<h2><a href=" . "$anchor>" . "Transmit</a> the compressed tar image</h2>\n";
  113.   $urlline = "<FORM ACTION=\"/toolbox/www/cgi-bin/sendrm-cgi?$abstmpdirpathNfile\" METHOD=\"POST\"> <INPUT TYPE=\"submit\" VALUE=\"Transmit\"> the compressed tar image</FORM><br>\n";
  114.  
  115.   # 11. AND FINALLY, create the final html-crap seen in the body of this doc:
  116.   print "The size of the compressed tar image you are about to transmit is  ";
  117.   print "<b>$size BYTES</b><br>";
  118.   print $urlline, "<br>\n";
  119.   print "FYI:  <i>Depending on which broswer yer using</i>, when prompted \n";
  120.   print " with the \"Save As\" window, if filename is missing, it's \n";
  121.   print "intended name should be: <h2>$dir2tar.tar</h2>\n";
  122.  
  123.   print "<pre> \n\n </pre>";
  124.  
  125. } else {
  126.  
  127.   open (INFILE, "> /usr/tmp/tar-cgi.Failure");
  128.   $val = "system call for maketar failed returning:  $res\n";
  129.   syswrite(INFILE,$val,length($val));
  130.   syswrite(INFILE,$maketar,length($maketar));
  131.   $val = "\n";
  132.   syswrite(INFILE,$val,length($val));
  133.   close (INFILE);
  134.  
  135.   # we failed, so print out failure header
  136.   &header_failure ;
  137.  
  138.   print "Oh-oh -- something messed-up with the system call ";
  139.   print "to generate the compressed tar archive. \n";
  140.   print "<p>\n";
  141.   print "See <b>/usr/tmp/tar-cgi.Failure</b> for more information.\n";
  142.   print "<p>\n";
  143.   print "pleeze send ";
  144.   print "mail to ";
  145.   print "<a href=\"mailto:DTjanitor\@sgi.com\"><b>DTjanitor\@sgi.com</b> ";
  146.   print "</a>(this link <i>doesn't work</i> in xmosaic)--be sure \n";
  147.   print "to include yer own e-mail address and <i>where you were</i> ";
  148.   print "when you attempted to initiate generation of the compressed ";
  149.   print "tar file.  many thanx from the webDT tenderfoot...";
  150.  
  151. }
  152.  
  153. print "<hr size=\"6\">\n";
  154. print "</body>\n";
  155. print "</html>\n";
  156.  
  157.  
  158.  
  159.  
  160. # *********************************************************
  161. # subroutine for successful compressed-tar file generation:
  162. # lay in the html header/beginning text stuff:
  163. sub header_success
  164. {
  165.     print "<html><head><title>DT cgi generation of compressed-tar-file for Entire Dir SUCCESSFUL</title></head><body>";
  166.     print "<h1>Developer Toolbox:  Successful Generation of Compressed Tar Image for Entire Directory</h1>";
  167.     &navigator_line
  168. }
  169.  
  170. # ************************************************************
  171. # subroutine header for failed compressed-tar file generation:
  172. # lay in the html header/beginning text stuff:
  173. sub header_failure
  174. {
  175.     print "<html><head><title>DT cgi generation of compressed-tar-file for Entire Dir FAILURE</title></head><body>";
  176.     print "<h1>Developer Toolbox:  Failure for Generation of Compressed Tar Image for Entire Directory</h1>";
  177.     &navigator_line
  178. }
  179.  
  180.  
  181.  
  182. # *********************************************************
  183. # subroutine for successful compressed-tar file generation:
  184. # lay in the html header/beginning text stuff:
  185. sub navigator_line
  186. {
  187.     print "<h3><a href=\"/toolbox/DT.html\">HUB</a> | <a \n";
  188.     print "href=\"/toolbox/www/cgi-bin/pheedbak-cgi/toolbox/www/cgi-bin?tar-cgi\">Pheedbak</a> | \n";
  189.     print "<a href=\"/toolbox/DTtree.html\">Tree</a> | \n";
  190.     print "<a href=\"/toolbox/DTtopic.html\">Topic</a> | \n";
  191.     print "<a href=\"/toolbox/DTalfabetic.html\">A-Z</a> | \n";
  192.     print "<a href=\"/toolbox/www/cgi-bin/DTsearch-cgi\">Search</a> | \n";
  193.     print "<a href=\"/toolbox/DThot.html\">Hot</a> | \n";
  194.     print "<a href=\"/toolbox/DTnew.html\">New</a></h3>";
  195.     print "<hr size=\"4\">\n";
  196. }
  197.  
  198. sub docroot_failure
  199. {
  200.     print "<html><head><title>DOCROOT environment variable not set FAILURE</title></head><body>";
  201.     print "<h1>DOCROOT environment variable not set FAILURE</h1>";
  202.     print "<p>\n";
  203.     foreach $f (`env`) {
  204.     print "<br>$f";
  205.     }
  206.     print "<p>\n";
  207.     &navigator_line;
  208.   print "pleeze send ";
  209.   print "mail to ";
  210.   print "<a href=\"mailto:DTjanitor\@sgi.com\"><b>DTjanitor\@sgi.com</b> ";
  211.   print "</a>(this link <i>doesn't work</i> in xmosaic)--be sure \n";
  212.   print "to include yer own e-mail address and <i>where you were</i> ";
  213.   print "when you attempted to initiate generation of the compressed ";
  214.   print "tar file.  many thanx from the webDT tenderfoot...";
  215.   exit;
  216. }
  217.